/**
 * 获取北京时间
 *
 * @format
 * @param day 时间戳| string类型
 */

export const transformBeijingDate = (day: number | string) => {
  let time = new Date().getTime()
  if (day) {
    if (typeof day === 'string') {
      day = day.replace(/-/g, '/')
    }
    time = new Date(day).getTime()
  }
  return new Date(time + 8 * 60 * 60 * 1000)
}

/**
 * 获取开始时间
 * @param day
 */
export const getStartTimestamp = (day: string) => {
  if (!day) {
    throw new Error('参数不能为空')
  }
  day = day.replace(/-/g, '/')
  const date = new Date(`${day} 00:00:00`).getTime()
  const start = date - 8 * 60 * 60 * 1000
  return start
}

/**
 * 获取结束时间
 * @param day
 */
export const getEndTimestamp = (day: string) => {
  if (!day) {
    throw new Error('参数不能为空')
  }
  day = day.replace(/-/g, '/')
  const date = new Date(`${day} 23:59:59`).getTime()
  const end = date - 8 * 60 * 60 * 1000
  return end
}
